package com.xhwl.centiotdata.service.impl;

import com.alibaba.fastjson.JSON;
import com.xhwl.centiotdata.emq.EmqClient;
import com.xhwl.centiotdata.emq.QosEnum;
import com.xhwl.centiotdata.service.IEmqService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: pengxiao
 * @create: 2022-06-22 17:37
 **/

@Service
public class EmqServiceImpl implements IEmqService {

    @Autowired
    private EmqClient emqClient;

    /**
     * 消息发送至empx
     * @param noticeTopic
     * @param projectId
     * @param pwdKey
     */
    @Override
    public void sendToEmp(String noticeTopic, String projectId, Object pwdKey) {
        // 更新成功时下发至设备端
        Map<String, Object> retMap = new HashMap<>();
        retMap.put("projectId", projectId);
        retMap.put("result", pwdKey);
        emqClient.publish(noticeTopic + "/" + projectId, JSON.toJSONString(retMap), QosEnum.QoS1, false);
    }
}
